#!/usr/bin/env ruby
$stderr.puts "#{Time.now} Loading reprocess script"
require ::File.expand_path('../../config/environment',  __FILE__)

puts "if you aren't running this on a copy of the db..."
puts "you already fucked up, hit ctrl-c now"
gets

livectf_services = %w{
livectf_quals livectf_finals
}.map do |service_name|
  Service.find_by(name: service_name)
end

Flag.delete_all
Flag.initial_distribution
Flag.collect_livectf_flags livectf_services

Capture.delete_all
Penalty.delete_all
Round.update_all distribution: nil, signature: nil, payload: nil

rounds = Round.order(id: :asc).all
services = Service.all

puts "preparing to reprocess #{rounds.count} rounds"

rounds.each do |r|
  print "\r#{r.id}"
  r.finalize!
end
puts
